import http from '../../utils/request'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        xueke:'',
        xueduan:'',
        activeHover:0,
        activeIndex:0
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.getmh() //获取学段
        this.getXueke(11739)//获取学科
        this.getTypeRes() //获取资源
        this.getspecial() //获取专题
        this.getTime() //适应时间
        this.getArea() //适应地区
        this.data.xueduan = '高中'
        this.data.xueke = '语文'
		this.data.xueduanId = 11739
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },
    //获取学段
    tabChange(e){
        let id=e.currentTarget.dataset.id
        let index = e.currentTarget.dataset.index
        let name = e.currentTarget.dataset.name
        this.getXueke(id)
        this.setData({activeHover:index,xueduan:name})
    },
    async getmh(){
        let that = this
        let options={
                url:'/getNavs5',
                method:'POST',
                data:{id:0},
                header:{"content-type":"application/json;charset=UTF-8"}
            }
        let res = await http(options)
        let datas = res.data.filter(item=> item.name!='不限')
        that.setData({list:datas})
    },
    //获取学科
    navSelect(e){
        let name = e.currentTarget.dataset.name
        let index = e.currentTarget.dataset.index
        this.setData({activeIndex:index,xueke:name})
    },
    async getXueke(id){
        let that = this
        let options={
                url:'/getNavs5',
                method:'POST',
                data:{id:id},
                header:{"content-type":"application/json;charset=UTF-8"}
            }
        let res = await http(options)
        let datas = res.data.filter(item=> item.name!='不限')
        that.setData({leftNav:datas})
    },
    //获取资源类型
    leixingCs(e){
        let id=e.currentTarget.dataset.id
        let {xueduan,xueke} = this.data
        let params={
            xueduanleixing:'iconitemcaseId',
            xueduanId:id,
            xueduan:xueduan?xueduan:'',
            xueke:xueke
        }
        let classifyQuery = JSON.stringify(params)
        console.info(classifyQuery)
        // return false
        wx.navigateTo({
            url: '/pages/resoucelist/resoucelist?classifyQuery='+classifyQuery
        });
    },
    async getTypeRes(){
        let that = this
        let options={
                url:'/getIconItemcaseType',
                method:'POST'
            }
        let res = await http(options)
        that.setData({resoucelist:res.data.obj})
    },
    //获取专题分类
    sfenleiCs(e){
        let id=e.currentTarget.dataset.id
        wx.navigateTo({
            url: '/pages/speciallist/speciallist?id='+id
        });
    },
    async getspecial(){
        let that = this
        let options={
                url:'/getlanguage',
                method:'POST'
            }
        let res = await http(options)
        that.setData({specialclassify:res.data.obj})
    },
    //适应时间
    timeCs(e){
        let id= e.currentTarget.dataset.id
        let {xueduan,xueke} = this.data
        let params={
            time:id,
            timeName:'适应时间',
            xueduan:xueduan,
            xueke:xueke
        }
        let classifyQuery = JSON.stringify(params)
        wx.navigateTo({
            url: '/pages/resoucelist/resoucelist?classifyQuery='+classifyQuery
        });
    },
    async getTime(){
        let that = this
        let options={
                url:'/getLabelitemcase',
                method:'POST'
            }
        let res = await http(options)
        res.data.obj.map(item=>item.nameNumber=parseInt(item.name))
        res.data.obj.sort((a, b) => a.nameNumber - b.nameNumber)
        that.setData({datatime:res.data.obj.reverse()})
    },
    //适应地区
    areaCs(e){
        let id=e.currentTarget.dataset.id
        let {xueduan,xueke} = this.data
        let params={
            area:id,
            timeName:'适应地区',
            xueduan:xueduan,
            xueke:xueke
        }
        let classifyQuery = JSON.stringify(params)
        wx.navigateTo({
            url: '/pages/resoucelist/resoucelist?classifyQuery='+classifyQuery
        });
    },
    async getArea(){
        let that = this
        let options={
                url:'/getSubject',
                method:'POST'
            }
        let res = await http(options)
        if(res.data.code==0){
            let datalist=[]
           res.data.obj.map(item=>{
                datalist.push({subjectname:item.subjectname.replace('省','').replace('市',''),id:item.id})
           })
           that.setData({area:datalist})
        }
        
    }
})